package AnalyzeEtlLog

/**
 * Created by g705353 on 3/13/14.
 */

def cli = new CliBuilder( usage: "${this.class.name}.groovy [options...] <file name>" )

cli.h( longOpt: 'help', 'usage information' )

def opt = cli.parse( args )

if ( opt.h ) {
    cli.usage()
    System.exit 1
}
if(opt.arguments().size() == 0) {
    println("Please provide an ETLDrvier log file.")
    cli.usage()
    System.exit 1
}

def files = opt.arguments()
def fileName = files[0]

def rLogFile = new File(fileName)
def i = 0
def mCycleNum

def curMicroCycle
def startJobSet =          "BUILD_COUNTRY"
def finishJobSet =         "CYCLE_COMPLETE"
def aStart
def bStart
def aEnd
def bEnd
def auditId
def mCyclyStarted = false

def auditReg = /====Got audit ID \[(\d+)\].*/
//matcher = ("====Got audit ID [1417]" =~ auditReg)
//if (matcher.matches()) {
//    matcher.each {
//        println it[1]
//    }
//    auditId = matcher[0]
//    println("get audit id: $auditId ")
//}else{
//    println "not match"
//}
//return

rLogFile.eachLine {
    i++
    if (i > 20000) return

    if (it.startsWith("====Got Cycle ID [")) {
        mCyclyStarted = true
    }
    if (mCyclyStarted) {
        if (it.startsWith("====Got audit ID [")) {
            matcher = (it =~ auditReg)
            if (matcher.matches()) {
                auditId = matcher[0][1]
                println("get audit id: $auditId ")
            }
        }
    }

    //if (!it.startsWith('def version')) {return}
//    println evaluate(it) // Evaluates the line and prints the version
//    println it // Evaluates the line and prints the version
}